import React, { Component } from 'react'
import {
  BrowserRouter as Router,
  Switch,
  Route,
  Redirect
} from 'react-router-dom'
import Login from './Login'
import Layout from './Layout'
import NotFound from '../router-nest/NotFound'
import Slot from '../slot/index'
import Test from './Test'
import AuthRoute from './AuthRoute'

export default class index extends Component {
  render () {
    return (
      <Router>
        <Switch>
          <Route path='/login'>
            <Login />
          </Route>
          {/* <Route
            path='/layout'
            render={props => {
              const token = localStorage.getItem('token')
              if (token) {
                return <Layout />
              } else {
                return (
                  <Redirect to={`/login?redirect=${props.location.pathname}`} />
                )
              }
            }}
          /> */}
          <AuthRoute path='/layout' component={Layout} />
          <AuthRoute path='/test'>
            <Test />
          </AuthRoute>
          <Redirect exact from='/' to='/login' />
          <Route path='/slot' component={Slot} />
          <Route path='/' component={NotFound} />
        </Switch>
      </Router>
    )
  }
}
